package com.niit.project.controller;

import com.niit.project.entity.Goods;
import com.niit.project.entity.Page;
import com.niit.project.entity.User;
import com.niit.project.service.GoodsService;
import com.niit.project.service.impl.GoodsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.util.List;

//用户商品信息的更新
@WebServlet(name = "UserGoodsListController", value = "/UserGoodsListController")
public class UserGoodsListController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String pageIndex = request.getParameter("pageIndex");
        if(pageIndex == null)
        {
            pageIndex = "1";
        }


        Page page = new Page(Integer.valueOf(pageIndex));
        HttpSession session = request.getSession();
        GoodsService goodsService = new GoodsServiceImpl();
        List<Goods> goods = goodsService.showAllByPage(page);
        User user = (User) request.getAttribute("user");
        request.setAttribute("goods",goods);
        request.setAttribute("page",page);


        request.getRequestDispatcher("/UserGoodsList.jsp").forward(request,response);
    }
}
